package com.lin.manager.common.ex;

import com.lin.manager.common.resp.R;
import com.lin.manager.common.resp.RespCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.UndeclaredThrowableException;

/**
 * @作者: 林江
 * @创建时间: 2024/3/12
 * @功能:
 */
@Slf4j
@RestControllerAdvice
public class BizExceptionController {
    @ExceptionHandler(value = BizException.class)
    public R e(BizException e) {
        log.error("自定义异常信息：{}", e);
        return R.fail(e.getCode(), e.getMessage(), null);
    }

    @ExceptionHandler(value = UndeclaredThrowableException.class)
    public R runtimeException(InvocationTargetException e) {
        log.error("Aop执行异常信息：{}", e);
        return R.fail(RespCode.FAIL.getCode(), e.getTargetException().getMessage(), null);
    }

    @ExceptionHandler(value = Exception.class)
    public R runtimeException(Exception e) {
        log.error("全局异常信息：{}", e);
        return R.fail(RespCode.FAIL.getCode(), e.getMessage(), null);
    }


}
